package com.mundoa3.screen;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.mundoa3.Assets;
import com.mundoa3.SpaceWarsGame;

public class GameScreen implements Screen {
	
	//Global Variable
	private SpaceWarsGame game;
	
	private OrthographicCamera cam;
	private SpriteBatch batcher;
	
	public GameScreen(SpaceWarsGame game){
		this.game = game;
		
		cam = new OrthographicCamera(7, 9);
		cam.position.set(7f/2 ,9f/2, 0);
		batcher = new SpriteBatch();
		
	}
	
	@Override
	public void dispose() {
		batcher.dispose();
	}

	@Override
	public void hide() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void pause() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void render(float delta) {
		
		if (Gdx.input.justTouched()){
			game.setOver();
			return;
		}
		
		GL10 gl = Gdx.graphics.getGL10();
		gl.glClearColor(1,0,0,1);
		gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
		
		cam.update();
		batcher.setProjectionMatrix(cam.combined);
		
		batcher.disableBlending();		
		batcher.begin();
		batcher.draw(Assets.background, 0, 0, 7, 9);
		batcher.draw(Assets.points, 0, 8, 3, 1);
		batcher.end();
		
		batcher.enableBlending();
		batcher.begin();
		batcher.draw(Assets.ship, 3, 1, 1, 1);
		batcher.end();
		
	}

	@Override
	public void resize(int width, int height) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void resume() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void show() {
		// TODO Auto-generated method stub
		
	}

}
